﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	
	Dim edtServerIP As EditText
	Dim edtServerPort As EditText
	Dim btnConn As Button
	Dim btnSave As Button
	
	Dim sSql As String
	Dim bConnOk As Boolean
	
	Dim HttpJobTool As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormLoginConfig")
	Activity.Title = "选项"
	
	InitData
	
	InitLayOut

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitData

	bConnOk = False
	edtServerIP.Text = PublicVar.GV_ServerIP
	edtServerPort.Text = PublicVar.GV_ServerPort
End Sub

Sub InitLayOut
	If edtServerIP.Text = "" Then
		edtServerIP.RequestFocus
	Else If edtServerPort.Text = "" Then
		edtServerPort.RequestFocus
		
	End If
End Sub

Sub btnSave_Click
	If edtServerIP.Text.Trim = "" Then
		ToastMessageShow("请输入服务器IP!",False)
		edtServerIP.RequestFocus
		Return		
	End If
	
	If edtServerPort.Text.Trim = "" Then
		ToastMessageShow("请输入服务器端口!",False)
		edtServerPort.RequestFocus
		Return		
	End If
	
	PublicVar.GV_ServerIP = edtServerIP.Text.Trim
	PublicVar.GV_ServerPort = edtServerPort.Text.Trim
	
	sSql = "UPDATE ZD_CONFIG SET SERVERIP='"&PublicVar.GV_ServerIP&"',SERVERPORT="&PublicVar.GV_ServerPort
	Log("SQL: " & sSql)
	Try
		PublicVar.GV_SQLTool.ExecNonQuery(sSql)
	Catch
		ToastMessageShow("设置失败!",False)
		Log(LastException.Message)
		Return
	End Try
	ToastMessageShow("设置成功!",False)
End Sub

Sub btnConn_Click
	Dim sURL,sText As String
	
	sURL = PublicVar.GetServerUrl & "/init" 
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)

	ProgressDialogShow("正在连接服务器，请稍候...")	
	
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub


Sub HttpJobSuccess (Job As HttpJob)  
  ProgressDialogHide       
  bConnOk = True
  ToastMessageShow ("连接服务器成功", True)	
End Sub
Sub HttpJobError (Job As HttpJob) 
  ProgressDialogHide
	Dim sMsg As String
	
	Log("Error: " & Job.ErrorMessage)
	sMsg = "连接服务器失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
	
End Sub


